﻿using System;
using System.Collections;
using System.Text;
using System.Linq;

using Antlr.Runtime;
using Netium.Compiler;

namespace CFrontEnd
{
    using Trace = System.Diagnostics.Trace;
    using Debug = System.Diagnostics.Debug;

    partial class cParser
    {
        partial void EnterRule(string ruleName, int ruleIndex)
        {
            Debug.WriteLine("Entry rule: " + ruleName);
        }

        partial void LeaveRule(string ruleName, int ruleIndex)
        {
            Debug.WriteLine("Leave rule: " + ruleName);
        }

        public override string GetErrorMessage(Antlr.Runtime.RecognitionException e, string[] tokenNames)
        {
            var stack = GetRuleInvocationStack();

            string message = null;

            if (e is NoViableAltException)
            {
                var nvae = (NoViableAltException)e;
                message = " no viable alt: token=" + e.Token + " (decision = " + nvae.DecisionNumber + " state " + nvae.StateNumber + ")" + "decision=<<" + nvae.GrammarDecisionDescription + ">>";
            }
            else
            {
                message = base.GetErrorMessage(e, tokenNames);
            }

            message = stack + " " + message;
            System.Diagnostics.Trace.TraceError(message);

            return message;
        }
    }
}
